with System.Address_To_Access_Conversions;

package body PortAudioAda.Jack is

   package SATA is
     new System.Address_To_Access_Conversions (ICS.char_array_access);

   --------------------------
   -- PaJack_GetClientName --
   --------------------------

   function PaJack_GetClientName (errorCode : access PaError) return String
   is
      function Internal (n : System.Address) return PaError;
      pragma Import (C, Internal, "PaJack_GetClientName");

      cn  : aliased ICS.char_array_access;
   begin
      errorCode.all := Internal (SATA.To_Address (cn'Unchecked_Access));

      return s : String (1 .. Integer (ICS.Strlen (ICS.To_Chars_Ptr (cn)))) do
         s := ICS.Value (ICS.To_Chars_Ptr (cn));
      end return;
   end PaJack_GetClientName;

   --------------------------
   -- PaJack_SetClientName --
   --------------------------

   function PaJack_SetClientName (clientName : String) return PaError
   is
      function Internal (n : IC.char_array) return PaError;
      pragma Import (C, Internal, "PaJack_SetClientName");

      newClientName : constant access IC.char_array :=
                        new IC.char_array'(IC.To_C (clientName, True));
      pragma Convention (C, newClientName);
   begin
      return Internal (newClientName.all);
   end PaJack_SetClientName;

end PortAudioAda.Jack;
